package com.dtw.ditouwang.utils;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.dtw.ditouwang.R;

import java.util.HashMap;

import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatMoments;

public class ShareUtil {
    public static void share(Context context, final ShareParams shareParams) {
        final Dialog dialog = new Dialog(context, R.style.BottomDialog);
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.text_wechart:
                        JShareInterface.share(Wechat.Name, shareParams, new PlatActionListener() {
                            @Override
                            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                                Log.i("Dtw", "share complate");
                            }

                            @Override
                            public void onError(Platform platform, int i, int i1, Throwable throwable) {
                                Log.i("Dtw", "share error" + throwable.getMessage());
                                throwable.printStackTrace();

                            }

                            @Override
                            public void onCancel(Platform platform, int i) {
                                Log.i("Dtw", "share cancle");

                            }
                        });
                        dialog.dismiss();
                        break;
                    case R.id.text_friend:
                        JShareInterface.share(WechatMoments.Name, shareParams, new PlatActionListener() {
                            @Override
                            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                                Log.i("Dtw", "share complate");
                            }

                            @Override
                            public void onError(Platform platform, int i, int i1, Throwable throwable) {
                                Log.i("Dtw", "share error" + throwable.getMessage());
                                throwable.printStackTrace();

                            }

                            @Override
                            public void onCancel(Platform platform, int i) {
                                Log.i("Dtw", "share cancle");

                            }
                        });
                        dialog.dismiss();
                        break;
                    case R.id.text_qq:
                        break;
                    case R.id.text_qzone:
                        break;
                    case R.id.text_sina:
                        break;
                    case R.id.text_cancle:
                        dialog.dismiss();
                        break;
                }
            }
        };
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_share, null);
        dialogView.findViewById(R.id.text_wechart).setOnClickListener(onClickListener);
        dialogView.findViewById(R.id.text_friend).setOnClickListener(onClickListener);
        dialogView.findViewById(R.id.text_qq).setOnClickListener(onClickListener);
        dialogView.findViewById(R.id.text_qzone).setOnClickListener(onClickListener);
        dialogView.findViewById(R.id.text_sina).setOnClickListener(onClickListener);
        dialogView.findViewById(R.id.text_cancle).setOnClickListener(onClickListener);

        dialog.setContentView(dialogView);
        ViewGroup.LayoutParams layoutParams = dialogView.getLayoutParams();
        layoutParams.width = dialogView.getResources().getDisplayMetrics().widthPixels;
        dialogView.setLayoutParams(layoutParams);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM); // 此处可以设置dialog显示的位置
//                window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();
    }
}
